package com.fivestar.pmanager.core.base;

import java.util.List;

/**
 * 分页基类
 */
public class PageBean
{
    private int pageSize = 10;// 页大小
    private int pages;// 总页数
    private int pageNum;// 当前页
    private int total;// 总条数
    private List<?> rows;// 记录


    /**
     * @return the pageSize
     */
    public int getPageSize()
    {
        return pageSize <= 0 ? 10 : pageSize;
    }


    /**
     * @param pageSize the pageSize to set
     */
    public void setPageSize(int pageSize)
    {
        this.pageSize = pageSize;
    }


    /**
     * @return the pages
     */
    public int getPages()
    {
        return pages;
    }


    /**
     * @param pages the pages to set
     */
    public void setPages(int pages)
    {
        this.pages = pages;
    }


    /**
     * @return the pageNum
     */
    public int getPageNum()
    {
        return pageNum == 0 ? 1 : pageNum;
    }


    /**
     * @param page the page to set
     */
    public void setPageNum(int pageNum)
    {
        this.pageNum = pageNum;
    }


    /**
     * @return the total
     */
    public int getTotal()
    {
        return total;
    }


    /**
     * @param total the total to set
     */
    public void setTotal(int total)
    {
        this.total = total;
    }


    /**
     * @return the rows
     */
    public List<?> getRows()
    {
        return rows;
    }


    /**
     * @param rows the rows to set
     */
    public void setRows(List<?> rows)
    {
        this.rows = rows;
    }
    
    
    /**
     * 计算总页数
     *
     * @author shangk
     */
    public PageBean calcPages()
    {
        pages = total % pageSize == 0 ? total / pageSize : (total /pageSize) + 1;
        return this;
    }
    
    
    /**
     * 
     * 计算数据起始索引
     *
     * @author Administrator
     */
    public int calcStartIndex()
    {

        if (pageNum <= 0)
        {
            pageNum = 1;
        }
        else if (pages > 0 && pageNum > pages)
        {
            pageNum = pages;
        }

        return (pageNum - 1) * pageSize;
    }
}
